import ChartBase from './chart-base'
import { deepClone, mergeObject } from '@/utils'

export default class TableList extends ChartBase {
  constructor() {
    super()
  }

  // 基础描述
  _info = {
    name: '列表表格',
    type: 'table-list',// 图表类型

    group: 'table',// 图表分类
    component: 'table-list',
    icon: 'table-list'// 图表展示ICON
  }

  // 总 配置项
  _defaultOption = {
    tableField: [
      /*
        {
          key: '',
          fieldName: '',
          fieldDescribe: ''
        }
      */
    ],
    tableData: [],
    tableTotal: 0,
    config: {
      pagination: {
        show: true
      }
    },
    style: {}
  }
  // 系列
  _defaultSeries = {}

  // 数据结构描述
  _dataPoolConfig = [
    {
      label: '字段',
      key: 'tableField',
      type: ['string', 'date', 'number'],
      limit: -1
    }
  ]

  // 样式配置描述信息
  _styleOptionConfig = [
    /* {
       label: '固定表头',
       bindKeys: 'config.header.fixed',
       controlType: 'switch',
       controlValue: true,
       controlProps: {},
       controlConfigs: {}
     }*/
    {
      label: '分页',
      bindKeys: 'config.pagination.show',
      controlType: 'switch',
      controlValue: false,
      controlProps: {},
      controlConfigs: {}
    }
  ]

  getOption({ dataField = [], dataList = [], dataTotal = 0, dataPoolField, styleOptionConfig = [], themeColor = [] }) {

    this._updateDataPoolField(dataField, dataPoolField)

    let defaultOption = deepClone(this._defaultOption)

    let option = this._transformStyleOptionConfig(styleOptionConfig)

    defaultOption.tableField = dataPoolField['tableField']

    defaultOption.tableData = dataList
    defaultOption.tableTotal = dataTotal

    if (defaultOption && option) defaultOption = mergeObject(defaultOption, option)

    return defaultOption
  }

  getClickData(event) {

    return { ...event }
  }
}
